import Vue from 'vue'
import Router from 'vue-router'
import Login from './views/Login.vue'
import Home from './views/Home.vue'

Vue.use(Router)

const router=new Router({
  routes: [
    {
      path: '/login',
      name: 'login',
      component: Login
    },
    {
      path: '/',
      name: 'home',
      component: Home,
      // 当访问/是让路由重定向到欢迎页面
      redirect: { name: 'welcome' },
      children: [
        {
          path: '/welcome',
          name: 'welcome',
          // route level code-splitting
          // this generates a separate chunk (about.[hash].js) for this route
          // which is lazy-loaded when the route is visited.
          component: () => import(/* webpackChunkName: "welcome" */ './views/Welcome.vue')
        },
        {
          path: '/usergroup',
          name: 'usergroup',
          component: () => import(/* webpackChunkName: "usergroup" */ './views/Usergroup.vue')
        },
        {
          path: '/userslist',
          name: 'userslist',
          component: () => import(/* webpackChunkName: "userslist" */ './views/Userslist.vue')
        },
        {
          path: '/userslog',
          name: 'userslog',
          component: () => import(/* webpackChunkName: "userslog" */ './views/Userslog.vue')
        },
        {
          path: '/systemconfig',
          name: 'systemconfig',
          component: () => import(/* webpackChunkName: "systemconfig" */ './views/Systemconfig.vue')
        },
        {
          path: '/rightlist',
          name: 'rightlist',
          component: () => import(/* webpackChunkName: "rightlist" */ './views/Rightlist.vue')
        }
      ]
    }
  ]
})

// 路由跳转前的判断
// router.beforeEach((to, from, next) => {
//     if (to.path===('/login')) {
//       next()
//     } else {
//       let user = window.localStorage.getItem('isLogin');
//       if (!user) {
//         next({
//           path: '/login'
//         })
//       } else {
//         next()
//       }
//     }
// })

export default router
